function maxFrequencyElements(nums) {
  // 统计每个元素的频率
  const frequency = {};
  for (const num of nums) {
    frequency[num] = (frequency[num] || 0) + 1;
  }

  // 找出最大频率
  let maxFreq = 0;
  for (const key in frequency) {
    if (frequency[key] > maxFreq) {
      maxFreq = frequency[key];
    }
  }

  // 计算所有具有最大频率的元素的总频率
  let total = 0;
  for (const key in frequency) {
    if (frequency[key] === maxFreq) {
      total += frequency[key];
    }
  }

  return total;
}

// 测试示例
console.log(maxFrequencyElements([1, 2, 2, 3, 1, 4])); // 输出: 4
console.log(maxFrequencyElements([1, 2, 3, 4, 5])); // 输出: 5
